<template>
    <div id="OrdersTitle">
        <v-details :inputConfig="inputConfig" :detailData="inputData" :rules="rules" @pop="setdata"
                   ref="input"></v-details>
    </div>
</template>

<script>
import details from 'commons/Detail'
import baseMixin from "@/mixins/BaseMixin";

export default {
    props: {
        inputData: {
            type: Object,
        }
    },
    mixins: [baseMixin],
    name: "OrdersTitle",
    data() {
        return {
            newFlag: false,
        }
    },
    computed: {
        inputConfig() {
            if (this.newFlag) {
                return [
                    [
                        {
                            type: "input",
                            label: this.$t('ex.transferkey'),
                            props: "transferkey",
                            disabled: true
                        },
                        {
                            type: "table",
                            label: this.$t('ex.fromstorerkey'),
                            props: "fshippers",
                            tableConfig: [
                                {
                                    label: this.$t('config.shipper'),
                                    prop: "storerkey",
                                    input: "input",
                                },
                                {
                                    label: this.$t('config.company'),
                                    prop: "company",
                                    input: "input",
                                },
                                {
                                    label: this.$t('config.city'),
                                    prop: "city",
                                    input: "input",
                                },
                                {
                                    label: this.$t('config.provice'),
                                    prop: "state",
                                    input: "input",
                                },
                                {
                                    label: this.$t('config.postcode'),
                                    prop: "zip",
                                    input: "input",
                                },
                                {
                                    label: this.$t('config.contact'),
                                    prop: "contact",
                                    input: "input",
                                },
                                {
                                    label: this.$t('config.phone'),
                                    prop: "phone",
                                    input: "input",
                                }
                            ],
                            url: `/queryStorer/1/?/${this.$store.state.wms}`
                        },

                        {
                            type: "table",
                            label: this.$t('home.frtxshipstore'),
                            props: "frtxshipstore",
                            tableConfig: [
                                {
                                    label: this.$t('common.code'),
                                    prop: "code",
                                    input: "input",
                                },
                                {
                                    label: this.$t('common.desc'),
                                    prop: "description",
                                    input: "input",
                                },
                            ],
                            url: `/queryshipstore/${this.inputData.fshippers ? this.inputData.fshippers : undefined}/?/${this.$store.state.wms}`
                        }
                    ],
                    [
                        {
                            type: "input",
                            label: this.$t('in.externreceiptkey2'),
                            props: "externalno",
                        },
                        {
                            type: "table",
                            label: this.$t('ex.tostorerkey'),
                            props: "tshippers",
                            tableConfig: [
                                {
                                    label: this.$t('config.shipper'),
                                    prop: "storerkey",
                                    input: "input",
                                },
                                {
                                    label: this.$t('config.company'),
                                    prop: "company",
                                    input: "input",
                                },
                                {
                                    label: this.$t('config.city'),
                                    prop: "city",
                                    input: "input",
                                },
                                {
                                    label: this.$t('config.provice'),
                                    prop: "state",
                                    input: "input",
                                },
                                {
                                    label: this.$t('config.postcode'),
                                    prop: "zip",
                                    input: "input",
                                },
                                {
                                    label: this.$t('config.contact'),
                                    prop: "contact",
                                    input: "input",
                                },
                                {
                                    label: this.$t('config.phone'),
                                    prop: "phone",
                                    input: "input",
                                }
                            ],
                            url: `/queryStorer/1/?/${this.$store.state.wms}`
                        },

                        {
                            type: "table",
                            label: this.$t('home.trtxshipstore'),
                            props: "trtxshipstore",
                            tableConfig: [
                                {
                                    label: this.$t('common.code'),
                                    prop: "code",
                                    input: "input",
                                },
                                {
                                    label: this.$t('common.desc'),
                                    prop: "description",
                                    input: "input",
                                },
                            ],
                            url: `/queryshipstore/${this.inputData.tshippers ? this.inputData.tshippers : undefined}/?/${this.$store.state.wms}`
                        }
                    ],
                    [
                        {
                            type: "select",
                            label: this.$t('common.status'),
                            props: "status",
                            options: this.getOptions("codelkup/RTXTRANSFERSTA"),
                            disabled: true
                        },
                        {
                            type: "date",
                            label: this.$t('in.lottable05'),
                            props: "closedate",
                            disabled: true
                        },
                    ],
                    [
                        {
                            type: "date",
                            label: this.$t('home.expcteddate'),
                            props: "expcteddate",
                        },
                    ]
                ]
            } else {
                return [
                    [
                        {
                            type: "input",
                            label: this.$t('ex.transferkey'),
                            props: "transferkey",
                            disabled: true
                        },
                        {
                            type: "table",
                            label: this.$t('ex.fromstorerkey'),
                            props: "fshippers",
                            tableConfig: [
                                {
                                    label: this.$t('config.shipper'),
                                    prop: "storerkey",
                                    input: "input",
                                },
                                {
                                    label: this.$t('config.company'),
                                    prop: "company",
                                    input: "input",
                                },
                                {
                                    label: this.$t('config.city'),
                                    prop: "city",
                                    input: "input",
                                },
                                {
                                    label: this.$t('config.provice'),
                                    prop: "state",
                                    input: "input",
                                },
                                {
                                    label: this.$t('config.postcode'),
                                    prop: "zip",
                                    input: "input",
                                },
                                {
                                    label: this.$t('config.contact'),
                                    prop: "contact",
                                    input: "input",
                                },
                                {
                                    label: this.$t('config.phone'),
                                    prop: "phone",
                                    input: "input",
                                }
                            ],
                            url: `/queryStorer/1/?/${this.$store.state.wms}`,
                            disabled: true
                        },

                        {
                            type: "table",
                            label: this.$t('home.frtxshipstore'),
                            props: "frtxshipstore",
                            tableConfig: [
                                {
                                    label: this.$t('common.code'),
                                    prop: "code",
                                    input: "input",
                                },
                                {
                                    label: this.$t('common.desc'),
                                    prop: "description",
                                    input: "input",
                                },
                            ],
                            url: `/queryshipstore/${this.inputData.fshippers}/?/${this.$store.state.wms}`,
                            disabled: true
                        }
                    ],
                    [
                        {
                            type: "input",
                            label: this.$t('in.externreceiptkey2'),
                            props: "externalno",
                            disabled: true
                        },
                        {
                            type: "table",
                            label: this.$t('ex.tostorerkey'),
                            props: "tshippers",
                            tableConfig: [
                                {
                                    label: this.$t('config.shipper'),
                                    prop: "storerkey",
                                    input: "input",
                                },
                                {
                                    label: this.$t('config.company'),
                                    prop: "company",
                                    input: "input",
                                },
                                {
                                    label: this.$t('config.city'),
                                    prop: "city",
                                    input: "input",
                                },
                                {
                                    label: this.$t('config.provice'),
                                    prop: "state",
                                    input: "input",
                                },
                                {
                                    label: this.$t('config.postcode'),
                                    prop: "zip",
                                    input: "input",
                                },
                                {
                                    label: this.$t('config.contact'),
                                    prop: "contact",
                                    input: "input",
                                },
                                {
                                    label: this.$t('config.phone'),
                                    prop: "phone",
                                    input: "input",
                                }
                            ],
                            url: `/queryStorer/1/?/${this.$store.state.wms}`,
                            disabled: true
                        },

                        {
                            type: "table",
                            label: this.$t('home.trtxshipstore'),
                            props: "trtxshipstore",
                            tableConfig: [
                                {
                                    label: this.$t('common.code'),
                                    prop: "code",
                                    input: "input",
                                },
                                {
                                    label: this.$t('common.desc'),
                                    prop: "description",
                                    input: "input",
                                },
                            ],
                            url: `/queryshipstore/${this.inputData.fshippers}/?/${this.$store.state.wms}`,
                            disabled: true
                        }
                    ],
                    [
                        {
                            type: "select",
                            label: this.$t('common.status'),
                            props: "status",
                            options: this.getOptions("codelkup/RTXTRANSFERSTA"),
                            disabled: true
                        },
                        {
                            type: "date",
                            label: this.$t('in.lottable05'),
                            props: "closedate",
                            disabled: true
                        },
                    ],
                    [
                        {
                            type: "date",
                            label: this.$t('home.expcteddate'),
                            props: "expcteddate",
                            disabled: true
                        },
                        {
                            type: "select",
                            label: this.$t('in.receiptfinishflag'),
                            props: "transferfinishflag",
                            options: [
                                {code: 'P', description: 'P'},
                                {code: 'PS', description: 'PS'},
                                {code: 'PF', description: 'PF'},
                                {code: 'S', description: 'S'}
                            ]
                        },
                    ]
                ]
            }
        },
        rules() {
            return {
                transferkey: [
                    {required: true, trigger: 'blur'},
                ],
                fshippers: [
                    {required: true, validator: this.sku, trigger: 'blur'},
                ],
                /*frtxshipstore: [
                    {required: true, trigger: 'blur'},
                ],*/
                externalno: [
                    {required: true, trigger: 'blur'},
                ],
                tshippers: [
                    {required: true, validator: this.sku, trigger: 'blur'},
                ],
                /*trtxshipstore: [
                    {required: true, trigger: 'blur'},
                ],*/
                status: [
                    {required: true, trigger: 'blur'},
                ]
            }
        }
    },
    methods: {
        sku(rule, value, callback) {
            if (value === '') {
                callback(new Error());
            } else {
                this.$api.get(`/isExists/1/${value}/${this.$store.state.wms}`).then(res => {
                    
                        if (parseInt(res.bean) <= 0) {
                            this.$message.error(`不存在的货主:${value}`);
                            this.inputData[rule.field] = "";
                            callback(new Error());
                        } else {
                            callback()
                        }
                }).catch(e => {
                    this.$message.error(e);
                    callback(new Error());
                })
            }
        },
        setdata(data, id, close, listId) {
            if (listId == "0") {
                if (id == "1") {
                    this.inputData.fshippers = data.storerkey;
                } else if (id == "2") {
                    this.inputData.frtxshipstore = data.code;
                }
            } else if (listId == "1") {
                if (id == "1") {
                    this.inputData.tshippers = data.storerkey;
                } else if (id == "2") {
                    this.inputData.trtxshipstore = data.code;
                }
            }

            close(false);
        }
    },
    mounted() {
        if (Object.keys(this.$store.state.skip).length !== 0) {
            let data = this.$store.state.skip;
            this.newFlag = data.newFlag;
        } else {
            this.newFlag = this.$store.state.newFlag;
        }
    },
    watch: {},
    components: {
        'v-details': details
    }
}
</script>

<style scoped>

</style>
